package cn.dc406.labc406mgr.mapper;

import cn.dc406.labc406mgr.entity.Item;
import cn.dc406.labc406mgr.entity.ItemDetail;
import cn.dc406.labc406mgr.entity.LendDetail;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 用于给Items页面服务
 */
@Mapper
public interface ItemsMapper {
    @Select("select * from items")
    List<Item> selectItemList();

    @Select("select count(*) from items")
    int selectItemsSize();

    @Select("select * from items limit #{limit} offset #{offset}")
    List<Item> selectItemsLimited(int limit,int offset);
    //使用#{}时会添加引号
    //使用${}时不会添加任何东西
    @Select("select * from itemdetails where name like '%${iname}%' limit 1")
    ItemDetail selectItemDetailByName(String iname);

    @Insert("insert into lenddetails (username,itemid,num,state) value(#{username},${itemid},${num},#{state})")
    int insertLendDetails(LendDetail lendDetail);

}
